/** @namespace app.model.DataMark */
module.exports = app => {
  const {TINYINT, DATEONLY} = app.Sequelize;

  //采集 日期 记录
  const DataMark = app.model.define('data_mark', {
    type: {type: TINYINT(1).UNSIGNED, unique: 'type_and_date'},
    created_at: {type: DATEONLY, unique: 'type_and_date'},
  }, {updatedAt: false});

  DataMark.hasDailyDate = async (date) => {
    return 1 <=
        await app.model.DataMark.count({where: {type: 1, created_at: date}});
  };
  DataMark.hasDetailDate = async (date) => {
    return 1 <=
        await app.model.DataMark.count({where: {type: 2, created_at: date}});
  };
  DataMark.hasWeekDate = async (date) => {
    return 1 <=
        await app.model.DataMark.count({where: {type: 3, created_at: date}});
  };

  DataMark.setDailyDate = async (date) => {
    await app.model.DataMark.upsert({type: 1, created_at: date});
  };
  DataMark.setDetailDate = async (date) => {
    await app.model.DataMark.upsert({type: 2, created_at: date});
  };
  DataMark.setWeekDate = async (date) => {
    await app.model.DataMark.upsert({type: 3, created_at: date});
  };

  return DataMark;
};